local guhuo = fk.CreateSkill {

  name = "joy__guhuo",

  tags = {  },

}



guhuo:addEffect(fk.CardUseFinished, {
  name = "joy__guhuo",
  anim_type = "drawcard",
  derived_piles = "joy__guhuo",
  events = {fk.CardUseFinished,fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return target == player and player:hasSkill(guhuo.name) and ((data.damageDealt and player:getMark("joy__guhuo-turn") == 0) or not data.damageDealt) and data.card and (data.card.trueName == "slash" or data.card.is_damage_card)
    elseif event == fk.TurnEnd then
      return target == player and #player:getPile("joy__guhuo") > 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd and not player.dead then
      room:moveCardTo(player:getPile("joy__guhuo"), Card.PlayerHand, player, fk.ReasonPrey, guhuo.name)
    elseif event == fk.CardUseFinished then
      if data.damageDealt and not player.dead then
        room:setPlayerMark(player,"joy__guhuo-turn",1)
        player:drawCards(1,guhuo.name)
      elseif not data.damageDealt and not player.dead then
        if player.room:getCardArea(data.card) == Card.Processing then
          player:addToPile("joy__guhuo", data.card, true, guhuo.name)
          if not player.dead then
            player:drawCards(1,guhuo.name)
          end
        end
      end
    end
  end,
})
guhuo:addEffect(fk.TurnEnd, {
  name = "joy__guhuo",
  anim_type = "drawcard",
  derived_piles = "joy__guhuo",
  events = {fk.CardUseFinished,fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return target == player and player:hasSkill(guhuo.name) and ((data.damageDealt and player:getMark("joy__guhuo-turn") == 0) or not data.damageDealt) and data.card and (data.card.trueName == "slash" or data.card.is_damage_card)
    elseif event == fk.TurnEnd then
      return target == player and #player:getPile("joy__guhuo") > 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd and not player.dead then
      room:moveCardTo(player:getPile("joy__guhuo"), Card.PlayerHand, player, fk.ReasonPrey, guhuo.name)
    elseif event == fk.CardUseFinished then
      if data.damageDealt and not player.dead then
        room:setPlayerMark(player,"joy__guhuo-turn",1)
        player:drawCards(1,guhuo.name)
      elseif not data.damageDealt and not player.dead then
        if player.room:getCardArea(data.card) == Card.Processing then
          player:addToPile("joy__guhuo", data.card, true, guhuo.name)
          if not player.dead then
            player:drawCards(1,guhuo.name)
          end
        end
      end
    end
  end,
})

return guhuo